package com.leyou.search.entity;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.util.Map;

/**
 * @author zqq
 * @ClassName SearchRequest
 * @Description
 * @date 2020/3/8-20:03
 */
@ApiModel(value = "SearchRequest", description = "商品搜索参数类")
public class SearchRequest {

    /** 搜索条件 */
    @ApiModelProperty(value = "搜索条件，包含spu标题，分类名，甚至品牌名", name = "key")
    private String key;

    /** 搜索条件，分类id */
    @ApiModelProperty(value = "搜索条件，分类id", name = "cid")
    private Long cid;

    /** 搜索条件，分类id */
    @ApiModelProperty(value = "搜索条件，分类id对应的层级，1/一级分类、2/二级分类、3/三级分类", name = "grade")
    private Integer grade;

    /** 当前页 */
    @ApiModelProperty(value = "当前页", name = "page")
    private Integer page;

    /** 排序字段 */
    @ApiModelProperty(value = "排序字段", name = "sortBy")
    private String sortBy;

    /** 是否降序 */
    @ApiModelProperty(value = "是否降序", name = "descending")
    private Boolean descending;

    /** 过滤条件 */
    @ApiModelProperty(value = "过滤条件", name = "filter")
    private Map<String, Object> filter;

    public static final Integer DEFAULT_SIZE = 20;// 每页大小，不从页面接收，而是固定大小
    public static final Integer DEFAULT_PAGE = 1;// 默认页

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public Integer getPage() {
        if (page == null) {
            return DEFAULT_PAGE;
        }
        // 获取页码时做一些校验，不能小于1
        return Math.max(DEFAULT_PAGE, page);
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public String getSortBy() {
        return sortBy;
    }

    public void setSortBy(String sortBy) {
        this.sortBy = sortBy;
    }

    public Boolean getDescending() {
        return descending;
    }

    public void setDescending(Boolean descending) {
        this.descending = descending;
    }

    public Map<String, Object> getFilter() {
        return filter;
    }

    public void setFilter(Map<String, Object> filter) {
        this.filter = filter;
    }

    public Long getCid() {
        return cid;
    }

    public void setCid(Long cid) {
        this.cid = cid;
    }

    public Integer getGrade() {
        return grade;
    }

    public void setGrade(Integer grade) {
        this.grade = grade;
    }
}
